<?php require_once('../Connections/ConADMIN.php'); ?>
<?php
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") 
{
  $theValue = (!get_magic_quotes_gpc()) ? addslashes($theValue) : $theValue;

  switch ($theType) {
    case "text":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;    
    case "long":
    case "int":
      $theValue = ($theValue != "") ? intval($theValue) : "NULL";
      break;
    case "double":
      $theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" : "NULL";
      break;
    case "date":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;
    case "defined":
      $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
      break;
  }
  return $theValue;
}

$editFormAction = $_SERVER['PHP_SELF'];
if (isset($_SERVER['QUERY_STRING'])) {
  $editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']);
}

if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "form1")) {
  $insertSQL = sprintf("INSERT INTO Personagens (persoNome, persoApresentacao, persoForte, persoFraco, persoLicoes, persoInfo, persoVersiculo, persoObs) VALUES (%s, %s, %s, %s, %s, %s, %s, %s)",
                       GetSQLValueString($_POST['persoNome'], "text"),
                       GetSQLValueString($_POST['persoApresentacao'], "text"),
                       GetSQLValueString($_POST['persoForte'], "text"),
                       GetSQLValueString($_POST['persoFraco'], "text"),
                       GetSQLValueString($_POST['persoLicoes'], "text"),
                       GetSQLValueString($_POST['persoInfo'], "text"),
                       GetSQLValueString($_POST['persoVersiculo'], "text"),
                       GetSQLValueString($_POST['persoObs'], "text"));

  mysql_select_db($database_ConADMIN, $ConADMIN);
  $Result1 = mysql_query($insertSQL, $ConADMIN) or die(mysql_error());

  $insertGoTo = "#";
  if (isset($_SERVER['QUERY_STRING'])) {
    $insertGoTo .= (strpos($insertGoTo, '?')) ? "&" : "?";
    $insertGoTo .= $_SERVER['QUERY_STRING'];
  }
  // header(sprintf("Location: %s", $insertGoTo));
  print("document.location='../home/?cont=CadPersonagem&msg=Personagem cadastrado com sucesso!';");
}
?>
<table>
	<tr>
		<td>
			<h2>Cadastro de Personagens
		</h2></td>
	</tr>
	<?php if($_GET['msg']){ ?>
	<tr>
		<td id="MensagemSistema"><strong><?php echo $_GET['msg']; ?></strong>&nbsp;</td>
	</tr>
	<?php } ?>
	<tr>
		<td>
		
		<form method="post" name="form1" action="<?php echo $editFormAction; ?>">
			<table border="0" align="center" cellpadding="2" cellspacing="0" class="texto-1">
				<tr valign="baseline">
					<td align="right" valign="top" nowrap>Nome:</td>
					<td><input type="text" name="persoNome" value="" size="32"></td>
				</tr>
				<tr valign="baseline">
					<td align="right" valign="top" nowrap>Apresenta&ccedil;&atilde;o:</td>
					<td><textarea name="persoApresentacao" cols="80" rows="10"></textarea></td>
				</tr>
				<tr valign="baseline">
					<td align="right" valign="top" nowrap>Pontos fortes e &ecirc;xitos :</td>
					<td><textarea name="persoForte" cols="80" rows="10"></textarea></td>
				</tr>
				<tr valign="baseline">
					<td align="right" valign="top" nowrap>Pontos fracos e fracassos :</td>
					<td><textarea name="persoFraco" cols="80" rows="10"></textarea></td>
				</tr>
				<tr valign="baseline">
					<td align="right" valign="top" nowrap>Li&ccedil;&otilde;es de vida :</td>
					<td><textarea name="persoLicoes" cols="80" rows="10"></textarea></td>
				</tr>
				<tr valign="baseline">
					<td align="right" valign="top" nowrap>Informa&ccedil;&otilde;es essenciais :</td>
					<td><textarea name="persoInfo" cols="80" rows="10"></textarea></td>
				</tr>
				<tr valign="baseline">
					<td align="right" valign="top" nowrap>Vers&iacute;culo-chave:</td>
					<td><textarea name="persoVersiculo" cols="80" rows="10"></textarea></td>
				</tr>
				<tr valign="baseline">
					<td align="right" valign="top" nowrap>Observa&ccedil;&otilde;es:</td>
					<td><textarea name="persoObs" cols="80" rows="10"></textarea></td>
				</tr>
				<tr valign="baseline">
					<td align="right" valign="top" nowrap>&nbsp;</td>
					<td><input type="submit" value="Cadastrar"></td>
				</tr>
			</table>
			<input type="hidden" name="MM_insert" value="form1">
		</form>
		
		</td>
	</tr>
</table>
